﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Models;
using BLL;


namespace LinSM
{
    /// <summary>
    /// 配置连接
    /// </summary>
    public partial class Link : Form
    {
        public Link()
        {
            InitializeComponent();
        }
        LinkManager lm = new LinkManager();

        int type = 0;
        private void btnOk_Click(object sender, EventArgs e)
        {
            string ser = txtserver.Text.Trim();
            string db = txtDbname.Text.Trim();
            string id = txtuid.Text.Trim();
            string pwd = txtpwd.Text.Trim();
            string cha = txtCharset.Text.Trim();
            string code = txtCode.Text.Trim();
            if (ser == "" || db == "" || id == "" || pwd == "" || cha == "" )
            {
                MessageBox.Show("必填写项不能为空");
                return ;
            }
            //if (Encrypt.DecryptDES(txtCode.Text.Trim(), "12345678").Equals(ser))
            //{
            //    MessageBox.Show("注册成功！");
            //}
            //else
            //{
            //    MessageBox.Show("注册失败！");
            //}
            if (lm.isEncode(ser,db,id,pwd,cha,code))
            {
                type = 1;
                MessageBox.Show("配置成功");
                Login a = new Login();
                Close();
                a.Show();
            }
            else
            {
                MessageBox.Show("配置失败");
            }
        }

        private void txtserver_Leave(object sender, EventArgs e)
        {
            if (Config.autoCode)
            {
                txtCode.Text = Encrypt.EncryptDES(txtserver.Text.Trim(), Config.code);
            }
        }

        private void Link_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (type == 0)
            {
                Application.Exit();
            }
        }

        private void Link_Load(object sender, EventArgs e)
        {
            if (!Config.ipEdit)
            {
                txtserver.ReadOnly = true;
            }
            if (Config.autoCode)
            {
                txtCode.Text = "GR6dKhPqZZI4vvcj5u5sgg==";
            }
        }
    }
}
